
#include "BallGame.h"

void BallGame::onLoop(){

	if(bolasText.getBolas() <= 0)
	{
		gameOver = true;
		gameOverText.setVisivel(true);
	}

	if(level.getCurrentLevel() == -1)
	{
		won = true;
		wonText.setVisivel(true);
	}

	if(paused || gameOver || won)
	{
		CFPS::fpsControl.OnLoop();
		sprintf_s(captionString,"BallGame - FPS: %d  |  SpeedFactor: %.6f | %d",CFPS::fpsControl.getFPS(),CFPS::fpsControl.getSpeedFactor(),Level::objectiveBricks);
		SDL_WM_SetCaption(captionString,NULL);
		return;
	}

	for(unsigned int i=0; i< CEntity::entityList.size(); i++)
		if(CEntity::entityList[i])
				CEntity::entityList[i]->onLoop();

	if(!CEntity::entityEffects.empty())
		if( SDL_GetTicks() >= (unsigned) CEntity::entityEffects.top().offTime )
		{
			//Remove efeito
			CEntity::entityList[BARRA_INDEX]->removeEffectFlag(CEntity::entityEffects.top().effect);
			CEntity::entityList[BOLA_INDEX]->removeEffectFlag(CEntity::entityEffects.top().effect);
			CEntity::entityEffects.pop();
		}

	if(itemDesc.ativo)
		itemDesc.onLoop();

	level.onLoop();

	//Frame control
	CFPS::fpsControl.OnLoop();

	sprintf_s(captionString,"BallGame - FPS: %d  |  SpeedFactor: %.6f | %d",CFPS::fpsControl.getFPS(),CFPS::fpsControl.getSpeedFactor(),Level::objectiveBricks);
	SDL_WM_SetCaption(captionString,NULL);

	SDL_Delay(1);
}